﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Castle.ActiveRecord;
using NHibernate.Criterion;
using LIB;
using System.Collections;
using System.Web.UI.HtmlControls;
public partial class danh_muc_nha_quan_huyen : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                int quanHuyenID = ConvertUtility.ToInt32(Request.QueryString["quanHuyenID"]);
                int mucGiaID = ConvertUtility.ToInt32(Request.QueryString["mucGiaID"]);
                if (quanHuyenID > 0 && mucGiaID > 0)
                {
                    Category_Info phuongInfo = Category_Info.Find(quanHuyenID);
                    Category_Info quanInfo = phuongInfo.catParentID;

                    Category_Info mucGiaInfo = Category_Info.Find(mucGiaID);
                    hidQHID.Value = ConvertUtility.ToString(quanHuyenID);
                    hidMucGiaID.Value = ConvertUtility.ToString(mucGiaID);
                    litPos.Text = "<a href='/quan-huyen.aspx'>Quận huyện</a> ";
                    if (quanInfo.id != 42)
                        litPos.Text += "<img src='/images/bul4.png'> <a href='/quan-huyen/" + quanInfo.id + "/" + App_String.getTitleKhongDau(quanInfo.catName) + ".html'>" + quanInfo.catName + "</a>";
                    litPos.Text += " <img src='/images/bul4.png'> " + phuongInfo.catName + " <img src='/images/bul4.png'> " + mucGiaInfo.catName;

                    bindHome(quanHuyenID, mucGiaID);
                    seo(phuongInfo, mucGiaInfo);
                }
            }
        }
        catch (Exception ex) { }
    }
    protected void seo(Category_Info phuongInfo, Category_Info mucGiaInfo)
    {
        Page.Title = phuongInfo.catMetaTitle + "-" + mucGiaInfo.catMetaTitle ;
        //keywords
        HtmlMeta keywords = new HtmlMeta();
        keywords.Name = "keywords";
        keywords.Content = phuongInfo.catMetaKey + "-" + mucGiaInfo.catMetaKey;
        Page.Header.Controls.Add(keywords);
        //description
        HtmlMeta descriptions = new HtmlMeta();
        descriptions.Name = "description";
        descriptions.Content = phuongInfo.catMetaDes + "-" + mucGiaInfo.catMetaDes;
        Page.Header.Controls.Add(descriptions);
    } 
    protected void bindHome(int quanHuyenID,int mucGiaID)
    {
        Home_Info[] lstHome = Home_Info.searchHomeInQuanHuyen(quanHuyenID,mucGiaID,"", 0, "");

        repDanhMucNha.DataSource = lstHome.Take(16);
        repDanhMucNha.DataBind();

        int totalPage = (int)Math.Ceiling(ConvertUtility.ToDouble(lstHome.Length) / 16);
        pagerbot.Text = ConvertUtility.buildSimplePaging(totalPage, 1);
       
    }
}